(function () {
	var navWindow;
	
	var pathimage=Ti.App.Properties.getString('pathimage');
//	alert(pathimage)
	var i=0,bottom_bt=40,space=50,top=50
	
	
	//var win = Titanium.UI.currentWindow;
	var win = Ti.UI.createWindow({
		exitOnClose: true,
     	backgroundColor:'yellow',
        navBarHidden:true,
        fullscreen:true,
        backgroundImage:pathimage+'bg.png',
        title:'Màn hình chính'
    });
	
	
	
	
	// handle cross-platform navigation
    if (Lhs.isAndroid()) {
        Lhs.navGroup = {
            open: function (win, obj) {
                win.open(obj);
            },
            close: function (win, obj) {
                win.close(obj);
            }
        };
        navWindow = win;
    } else {
        navWindow = Ti.UI.createWindow();
        Lhs.navGroup = Ti.UI.iPhone.createNavigationGroup({
            window: win
        });
        navWindow.add(Lhs.navGroup);
    }

	
	
	
	
	
	var header0 = Titanium.UI.createView({
		top:0,
		width:Titanium.Platform.displayCaps.platformWidth,
		height:45,
		backgroundImage:pathimage+'bg_index_top.png',
	}); 
	
	
	
	var image_logo = Titanium.UI.createImageView({
		
		top:10,
		width:Titanium.Platform.displayCaps.platformWidth,
		height:Titanium.Platform.displayCaps.platformHeight-(5*Ti.App.Properties.getInt('heightbt_MainWindow')+Ti.App.Properties.getInt('bottombt_MainWindow')),
		image:pathimage+'logo_danhba.png',
		
	}); 
	
	win.add(image_logo)
	win.add(header0)
	/*
	
	var header1 = Titanium.UI.createView({
		top:header0.top+header0.height+top,
		width:Titanium.Platform.displayCaps.platformWidth-space,
		height:132,
		backgroundImage:pathimage+'bg_index_tip_top.png',
	}); 
	win.add(header1)
	var header2 = Titanium.UI.createView({
		top:header1.height+header1.top,
		width:Titanium.Platform.displayCaps.platformWidth-space,
		height:55,
		backgroundImage:pathimage+'bg_index_tip_middle.png',
	}); 
	win.add(header2)
	var header3 = Titanium.UI.createView({
		top:header2.height+header2.top,
		width:Titanium.Platform.displayCaps.platformWidth-space,
		height:61,
		backgroundImage:pathimage+'bg_index_tip_bottom.png',
	}); 
	win.add(header3)
	
	var image_cat = Titanium.UI.createImageView({
		right:space/2,
		top:header3.height+header3.top-210,
		image:pathimage+'img_pet_cat.png',
	}); 
	win.add(image_cat)
	var image_hello = Titanium.UI.createView({
		right:space/2,
		top:header3.height+header3.top-210-108,
		width:163,
		height:108,
		backgroundImage:pathimage+'bg_index_dialog.png',
	}); 
	win.add(image_hello)
	
	var image_text = Titanium.UI.createLabel({
		text:'Xin chào',
		font:{
				fontSize:23,
				fontWeight:'bold',
			 },
		color:'#6c3b2a'
			 
	}); 
	image_hello.add(image_text)
	
	*/
	
	var createButton = function (Buttons) {
	
		var vi = Titanium.UI.createView({
			 
			 width:Titanium.Platform.displayCaps.platformWidth,
			 height: Ti.App.Properties.getInt('heightbt_MainWindow'),//73,
			 bottom:Buttons.bottom,
			 //backgroundColor:Buttons[i].color,
		}); 
		var bt = Titanium.UI.createButton({
			
			 backgroundImage:Buttons.image,
			 backgroundSelectedImage:Buttons.imagepress,
			 width:Titanium.Platform.displayCaps.platformWidth,
			 height:Ti.App.Properties.getInt('heightbt_MainWindow'),//73
		     func:Buttons.func,
			 //bottom:bottom_bt,
		}); 
		
		bt.addEventListener('click', function (e) {
            var iconWin  =Buttons.func(Buttons.args);
            Lhs.navGroup.open(iconWin, {
                animated: true
            });
        });
        
		var text = Titanium.UI.createLabel({
			text:Buttons.title,
			font:{
					fontSize:Ti.App.Properties.getInt('fontsize_MainWindow'),//38,
					fontWeight:'bold',
				 },
			color:Buttons.color,
			right:Ti.App.Properties.getInt('righttext_MainWindow'),//100,
			width:'auto',
			height:'auto',
			touchEnabled:false,
		}); 
	    vi.add(bt)
		vi.add(text)
		return vi;
		
		//bottom_bt+=bt.height
	}
	for (i = 0; i < Lhs.ui.icons.Buttons.length; i++){
        win.add(createButton(Lhs.ui.icons.Buttons[i]));
    }
	//Add button to top
	var bt_top = Titanium.UI.createButton({
		 touchEnabled:false,
		 backgroundImage:pathimage+'bg_intex1_top.png',
		 width:Titanium.Platform.displayCaps.platformWidth,
		 height:Ti.App.Properties.getInt('height_top_bottombt_MainWindow') ,//28,
		 bottom:5*Ti.App.Properties.getInt('heightbt_MainWindow')+Ti.App.Properties.getInt('bottombt_MainWindow')   //405,
	}); 
	win.add(bt_top)

	
	
	///////////////////LOADING//////////////////////
	if (Lhs.isAndroid()) {
        win.open({
            animated: true
        });
    } else {
        navWindow.open({
            transition: Ti.UI.iPhone.AnimationStyle.CURL_DOWN
        });
    }
	

})();









